package container_cmds

import (
	"fmt"

	"atomgit.com/openlinksaas/devc/utils"
	"github.com/docker/docker/api/types"
	"github.com/docker/docker/client"
	"github.com/spf13/cobra"
)

var removeCmd = &cobra.Command{
	Use: "remove",
	PreRunE: func(cmd *cobra.Command, args []string) error {
		if len(args) != 1 {
			return fmt.Errorf("need param [containerId]")
		}
		return nil
	},
	RunE: runRemove,
}

func runRemove(cmd *cobra.Command, args []string) error {
	containerId := args[0]

	cli, err := client.NewClientWithOpts(client.FromEnv)
	if err != nil {
		return err
	}
	err = cli.ContainerRemove(cmd.Context(), containerId, types.ContainerRemoveOptions{
		Force: true,
	})
	if err != nil {
		return err
	}
	utils.PrintResult(true)
	return nil
}
